/*
 * main.c
 *
 *  Created on: 19.01.2013
 *      Author: Michael
 */

#include "stdio.h"
#include "flag.h"
#include "observer.h"

#define OBSERVERS 3

const observer gObservers[OBSERVERS] = {obs1, obs2, obs3};

int main(int argc, char** argv) {

	// bitmasking example
	Flag_t flags = FLAG1 | FLAG2;

	// should be ok
	if (flags & (FLAG1 | FLAG2)) {
		printf("%s\n", "FLAGS OK");
	} else {
		printf("%s\n", "FLAGS NOT OK");
	}

	Flag_t flags1 = FLAG1 | FLAG3;

	// shouldn't be ok
	if (flags1 & (FLAG2)) {
		printf("%s\n", "FLAGS OK");
	} else {
		printf("%s\n", "FLAGS NOT OK");
	}

	// observer example
	int j;

	// should print obs1 obs2 obs3
	for (j = 0; j < OBSERVERS; ++j) {
		gObservers[j]();
	}

	// const example
	int i = 6;
	const int* foo = &i; // declares that foo is a variable pointer to a constant integer
	int* const foo1 = &i; // declares that foo1 is constant pointer to a variable integer
	const int* const foo2 = &i; // declares that foo2 is constant pointer to a constant integer

	foo = &i; // pointer can be changed
	*foo = i; // value cannot be changed
	*foo1 = i; // content can be changed
	foo1 = &i; // pointer cannot be changed
	*foo2 = i; // value cannot be changed
	foo2 = &i; // pointer cannot be changed

	return 0;
}
